<template>
	<view class="page">
		<!-- 导航栏 -->
		<free-nav-bar title="标签好友列表" showBack :showRight="false"></free-nav-bar>
		
		<free-list-item v-for="item in list" :key="item.id" :title="item.name"
		@click="handle(item)" :cover="item.avatar || '/static/images/userpic.png'" 
		:showRight="true"></free-list-item>
	</view>
</template>

<script>
	import freeNavBar from "@/components/free-ui/free-nav-bar.vue"
	import freeListItem from "@/components/free-ui/free-list-item.vue"
	import $H from '@/common/free-lib/request.js'
	import auth from "@/common/mixin/auth.js"
	import { mapState } from "vuex"
	export default {
		data() {
			return {
				list:[],
				id: 0
			}
		},
		mixins:[auth],
		onLoad(e) {
			this.id = e.id
			this.getData()
		},
		methods: {
			getData(){
				return new Promise((resolve, reject)=>{
					$H.get('/tag/read/'+this.id).then(res=>{
						this.list = res.map(item=>{
							return {
								id: item.friendInfo.id,
								name: item.nickname || item.friendInfo.nickname || item.friendInfo.username,
								avatar: item.friendInfo.avatar
							}
						})
						console.log(res);
						resolve(res)
					})
				})
			},
			handle(item){
				uni.navigateTo({
					url: '/pages/mail/user-base/user-base?user_id=' + item.id
				});
			}
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.getData().then(res=>{
			uni.stopPullDownRefresh()
				uni.showToast({
					title: '刷新成功',
					icon:"none"
				});
			})
		},
		components:{
			freeNavBar,
			freeListItem
		}
	}
</script>

<style>

</style>
